/*
 * Copyright (C) 2016  Nicola Spanti (RyDroid) <dev@nicola-spanti.info>
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */


#include <check.h>
#include "PlanetWars2dRT-core/specific/model/universes.h"
#include "PlanetWars2dRT-core/specific/model/universe_planets.h"


struct universe_t a_universe;

void
tests_setup_free(void)
{
  universe_destructor(&a_universe);
}


void
test_universe_basic_getter(universe_basic_getter_t universe_getter)
{
  bool success;
  a_universe = universe_getter(&success);
  ck_assert(success);
}

START_TEST(test_line_3_planets)
{
  test_universe_basic_getter(get_universe_hard_coded_line_3_planets);
  ck_assert(universe_get_nb_planets(&a_universe) == 3);
}
END_TEST

START_TEST(test_line_4_planets)
{
  test_universe_basic_getter(get_universe_hard_coded_line_4_planets);
  ck_assert(universe_get_nb_planets(&a_universe) == 4);
}
END_TEST

START_TEST(test_line_5_planets)
{
  test_universe_basic_getter(get_universe_hard_coded_line_5_planets);
  ck_assert(universe_get_nb_planets(&a_universe) == 5);
}
END_TEST

START_TEST(test_triforce_small_6_planets)
{
  test_universe_basic_getter(get_universe_hard_coded_triforce_small_6_planets);
  ck_assert(universe_get_nb_planets(&a_universe) == 6);
}
END_TEST

START_TEST(test_square_not_filled_small_8_planets)
{
  test_universe_basic_getter(get_universe_hard_coded_square_not_filled_small_8_planets);
  ck_assert(universe_get_nb_planets(&a_universe) == 8);
}
END_TEST

START_TEST(test_square_filled_small_9_planets)
{
  test_universe_basic_getter(get_universe_hard_coded_square_filled_small_9_planets);
  ck_assert(universe_get_nb_planets(&a_universe) == 9);
}
END_TEST


Suite*
universe_hard_coded_suite(void)
{
  Suite* s = suite_create("Universes hard coded");
  
  TCase* tc_line = tcase_create("Line");
  tcase_add_checked_fixture(tc_line,
			    NULL, tests_setup_free);
  tcase_add_test(tc_line, test_line_3_planets);
  tcase_add_test(tc_line, test_line_4_planets);
  tcase_add_test(tc_line, test_line_5_planets);
  suite_add_tcase(s, tc_line);
  
  TCase* tc_triforce = tcase_create("Triforce");
  tcase_add_checked_fixture(tc_triforce,
			    NULL, tests_setup_free);
  tcase_add_test(tc_triforce, test_triforce_small_6_planets);
  suite_add_tcase(s, tc_triforce);
  
  TCase* tc_square = tcase_create("Square");
  tcase_add_checked_fixture(tc_square,
			    NULL, tests_setup_free);
  tcase_add_test(tc_square,
		 test_square_not_filled_small_8_planets);
  tcase_add_test(tc_square,
		 test_square_filled_small_9_planets);
  suite_add_tcase(s, tc_square);
  
  return s;
}

int
main(void)
{
  size_t number_failed;
  Suite* s;
  SRunner* sr;
  
  s = universe_hard_coded_suite();
  sr = srunner_create(s);
  
  srunner_run_all(sr, CK_NORMAL);
  number_failed = srunner_ntests_failed(sr);
  srunner_free(sr);
  
  return (number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}
